package xyz.heyaoshare.config.satoken.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

import static xyz.heyaoshare.exceptions.code.ErrorInfo.DEVICE_TYPE_NOT_EXIST;
import static xyz.heyaoshare.exceptions.customize.ServerException.exception;

/**
 * 登录设备类型
 * @author YueHe
 * @version 0.0.1
 * @since 2025/6/25 上午11:42
 */
@Getter
@AllArgsConstructor
public enum DeviceEnums {

    PC("PC"),
    APP("APP"),

    ;

    private final String value;


    /**
     * 判断给定值是否存在于枚举中
     *
     * @param value 要判断的值
     * @return 如果存在则返回true，否则返回false
     */
    public static Boolean isExist(String value) {
        for (DeviceEnums deviceEnums : DeviceEnums.values()) {
            if (Objects.equals(deviceEnums.getValue(), value)) {
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }

    public static DeviceEnums get(String value) {
        for (DeviceEnums deviceEnums : DeviceEnums.values()) {
            if (Objects.equals(deviceEnums.getValue(), value)) {
                return deviceEnums;
            }
        }
        throw exception(DEVICE_TYPE_NOT_EXIST);
    }

}